#include "Comm.hpp"
#include "Fifo.hpp"

int main()
{
    //获取key
    key_t key = getkeyOrdie();
    cout << "key: " << ToHex(key) << endl;
    
    //创建共享内存
    int shmid = CreateShm(key, defaultsize);
    cout << "shmid: " << shmid << endl;

    //挂接
    char* addr = (char*)AttachShm(shmid);
    cout << "attach success" << endl;

    //引入管道
    Fifo fifo;
    Sync syn;
    syn.OpenRead();

    //通信
    for(;;)
    {
        if(!syn.Wait()) break;
        cout << "addr message: " <<addr<<endl;
        sleep(1);
    }

    //去挂接
    DetachShm(addr);
    cout << "detach success" << endl;

    //删除共享内存
    DeleteShm(shmid);

    return 0;
}